package com.gwtplatform.samples.tab.client.aboutus;

import com.google.inject.Inject;

import com.guit.client.GuitPresenter;
import com.guit.client.binder.GuitBinder;
import com.guit.client.binder.ViewHandler;
import com.guit.client.place.Place;
import com.guit.client.place.PlaceName;
import com.gwtplatform.samples.tab.client.aboutdialog.AboutDialogPresenter;
import com.gwtplatform.samples.tab.client.aboutus.AboutUsPresenter.AboutUsBinder;
import com.gwtplatform.samples.tab.client.infopopup.InfoPopupPresenter;
import com.gwtplatform.samples.tab.client.main.MainPresenter;

@PlaceName("aboutus")
public class AboutUsPresenter extends GuitPresenter<AboutUsBinder> implements Place<Void> {

    public static interface AboutUsBinder extends GuitBinder<AboutUsPresenter> {
    }
    
    private final AboutDialogPresenter dialogBox;
    private final InfoPopupPresenter infoPopup;

    @Inject
    public AboutUsPresenter(final AboutDialogPresenter dialogBox, final InfoPopupPresenter infoPopup, MainPresenter mainPresenter) {
        this.mainPresenter = mainPresenter;
        this.dialogBox = dialogBox;
        this.infoPopup = infoPopup;
    }

    @ViewHandler
    public void details$click() {
        dialogBox.show();
    }

    @ViewHandler
    public void popupLink$click(int nativeEvent$clientX, int nativeEvent$clientY) {
        infoPopup.show(nativeEvent$clientX + 15, nativeEvent$clientY);
    }

    private final MainPresenter mainPresenter;

    @Override
    public void go(Void data) {
        mainPresenter.setAboutUs(getView());
    }
}
